var e = require("../../requests/request.js");

Page({
    data: {
        phoneno: "",
        vcode: "",
        buttonDisable: !1,
        verifyCodeTime: "获取验证码"
    },
    mobileInputEvent: function(e) {
        this.setData({
            phoneno: e.detail.value
        });
    },
    verifyCodeEvent: function() {
        var t = this, n = this.data.phoneno;
        if (!/^1\d{10}$/.test(n)) return wx.showToast({
            title: "手机号有误！",
            icon: "none"
        }), !1;
        var a = 60, o = setInterval(function() {
            a -= 1, t.setData({
                verifyCodeTime: a + "s后重发",
                buttonDisable: !0
            }), 0 == a && (clearInterval(o), t.setData({
                verifyCodeTime: "获取验证码",
                buttonDisable: !1
            }));
        }, 1e3), s = wx.getStorageSync("opid");
        e.sendSMS(n, s);
    },
    voteVcode: function(e) {
        this.setData({
            vcode: e.detail.value
        });
    },
    regist: function() {
        var t = this;
        if ("获取验证码" == t.data.verifyCodeTime) return wx.showToast({
            title: "请先获取验证码！",
            icon: "none"
        }), !1;
        var n = wx.getStorageSync("UserName"), a = wx.getStorageSync("UserAvatar"), o = wx.getStorageSync("UserStatus"), s = t.data.vcode, r = t.data.phoneno;
        null != n && null != a && null != s && "" != s && null != r && "" != r ? (wx.showLoading({
            title: "加载中"
        }), setTimeout(function() {
            wx.hideLoading();
        }, 2e3), wx.login({
            success: function(t) {
                if (t.code) {
                    var i = t.code;
                    e.getOpenId(i, function(t) {
                        var i = t.unionid;
                        if (null != i) if (null != o && 21 == o) {
                            var c = wx.getStorageSync("useractivatetoken");
                            e.activate(r, c, s, function(e) {
                                if (2 != e.Status) return wx.showToast({
                                    title: e.Message + "！",
                                    icon: "none"
                                }), !1;
                                wx.setStorageSync("UserName", e.Data.UserName), wx.setStorageSync("UserAvatar", e.Data.UserAvatar), 
                                wx.setStorageSync("UserId", e.Data.UserId), wx.setStorageSync("UserToken", e.Data.UserToken), 
                                wx.setStorageSync("UserStatus", ""), wx.navigateBack();
                            });
                        } else {
                            var u = 17;
                            wx.getSystemInfo({
                                success: function(e) {
                                    "ios" == e.platform && (u = 7);
                                }
                            }), e.regist(n, a, s, r, i, u, function(e) {
                                if (console.log(e), 2 != e.Status) return wx.showToast({
                                    title: e.Message + "！",
                                    icon: "none"
                                }), !1;
                                wx.setStorageSync("UserName", e.Data.UserName), wx.setStorageSync("UserAvatar", e.Data.UserAvatar), 
                                wx.setStorageSync("UserId", e.Data.UserId), wx.setStorageSync("UserToken", e.Data.UserToken), 
                                wx.setStorageSync("UserStatus", ""), wx.navigateBack();
                            });
                        }
                    });
                }
            }
        })) : wx.showToast({
            title: "请输入正确的手机号和验证码！",
            icon: "none"
        });
    },
    networkWord: function() {
        wx.navigateTo({
            url: "../network/network"
        });
    },
    secretWord: function() {
        wx.navigateTo({
            url: "../secret/secret"
        });
    },
    onLoad: function(e) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});